//
//  UIButton+Extensions.swift
//  WeiboSwift
//
//  Created by hfwd on 2017/5/10.
//  Copyright © 2017年 hfwd. All rights reserved.
//

import UIKit

extension UIButton {
  
    
    /// 创建一个点击高亮的按钮
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize
    ///   - target: target
    ///   - action: action
    /// - Returns: button
    func createHighlightedColorBtn(title : String, fontSize : CGFloat = 16, target:AnyObject?, action:Selector) -> UIButton {
    
        let button = createBtn(title: title, fontSize : fontSize, normalColor: UIColor.blue, highLightedColor: UIColor.green, bgImageName: "")
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        return button
    }
    
    
    /// 创建一个按钮
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize
    ///   - normalColor: normalColor
    ///   - highLightedColor: highLightedColor
    ///   - bgImageName: bgImageName
    /// - Returns: UIButton
    func createBtn(title : String, fontSize : CGFloat = 16, normalColor:UIColor, highLightedColor:UIColor, bgImageName:String) -> UIButton {
        
        let button = UIButton()
        
        button.setTitle(title, for: .normal)
        
        button.sizeToFit()
        
        button.setTitleColor(normalColor, for: .normal)
        
        button.setTitleColor(highLightedColor, for: .highlighted)
        
        button.setBackgroundImage(UIImage(named:bgImageName), for: .normal)

        return button
    }
}
